package com.amt.olcacon.controller.doc;

import com.amt.olcacon.db.DerbyConfig;
import com.amt.olcacon.entity.DocExchangeProductEntity;
import com.amt.olcacon.service.IDocService;
import com.amt.olcacon.service.ImportAndCalcResultsService;
import com.amt.olcacon.utils.DateUtils;
import com.amt.olcacon.utils.MinioUtil;
import com.amt.olcacon.vo.GlobalResponse;
import com.deepoove.poi.XWPFTemplate;
import lombok.extern.slf4j.Slf4j;
import org.openlca.core.DataDir;
import org.openlca.core.database.ImpactMethodDao;
import org.openlca.core.database.ProcessDao;
import org.openlca.core.math.SystemCalculator;
import org.openlca.core.model.CalculationSetup;
import org.openlca.core.model.Process;
import org.openlca.core.results.LcaResult;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: yangyusheng
 * @Date: 2025/05/28
 */
@Slf4j
@RestController
@RequestMapping("olca/doc")
public class DocController {

    private final ResourceLoader resourceLoader;
    private final IDocService docService;
    private final ImportAndCalcResultsService importAndCalcResultsService;

    public DocController(ResourceLoader resourceLoader, IDocService docService, ImportAndCalcResultsService importAndCalcResultsService) {
        this.resourceLoader = resourceLoader;
        this.docService = docService;
        this.importAndCalcResultsService = importAndCalcResultsService;
    }

    @GetMapping("/generateReport")
    public GlobalResponse<String> generateReport(
            @RequestParam("processId") Long processId,
            @RequestParam("modelId") Long modelId,
            @RequestParam("impactMethodId") Long impactMethodId,
            @RequestParam("taskId") Long taskId,
            @RequestParam("resultId") Long resultId,
            @RequestParam("tblProcessId") Long tblProcessId,
            @RequestParam("templatePath") String templatePath
    ) throws Exception {
       return docService.generateReport(processId, modelId, impactMethodId,taskId,resultId,tblProcessId,templatePath);
    }

    @GetMapping("/importAndCalcResults")
    public void addTree(@RequestParam("filePath") String filePath) {
        importAndCalcResultsService.addTree(filePath);
    }

    @GetMapping("/clearCalcResults")
    public void clearCalcResults() {
        importAndCalcResultsService.clearCalcResults();
    }



}
